const filters = {
  // 时间处理工具

  fmtDate: function(val) {
    var t = new Date(val)
    var yy = t.getFullYear()
    var mm = (t.getMonth() + 1).toString().padStart(2, 0)
    var dd = t
      .getDate()
      .toString()
      .padStart(2, 0)
    var HH = t
      .getHours()
      .toString()
      .padStart(2, 0)
    var MM = t
      .getMinutes()
      .toString()
      .padStart(2, 0)
    var SS = t
      .getSeconds()
      .toString()
      .padStart(2, 0)
    return `${yy}-${mm}-${dd} ${HH}:${MM}:${SS}`
  },
  dateFormat: function(val) {
    var t = new Date(val)
    var yy = t.getFullYear()
    var mm = (t.getMonth() + 1).toString().padStart(2, 0)
    var dd = t
      .getDate()
      .toString()
      .padStart(2, 0)
    return `${yy}-${mm}-${dd}`
  },

  NumFormat: function(value) {
    var intPart = Number(value).toFixed(0) // 获取整数部分
    var intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') // 将整数部分逢三一断

    return intPartFormat
  }
}

export default (Vue) => {
  Object.keys(filters).forEach((key) => {
    Vue.filter(key, filters[key])
  })
}
